package com.neusoft.resturant.controller;

import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.ResBanner;
import com.neusoft.resturant.service.IResBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/api/banner")
public class ResBannerController {
    @Autowired
    private IResBannerService resBannerService;

    /**
     * 查询轮播图列表
     */
    @GetMapping("/list")
    public R list(ResBanner resBanner)
    {
        List<ResBanner> list = resBannerService.selectResBannerList(resBanner);
        return R.success(list);
    }


    /**
     * 获取轮播图详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {

        return R.success(resBannerService.selectResBannerById(id));
    }

    /**
     * 新增轮播图
     */
    @PostMapping
    public R add(@RequestBody ResBanner resBanner)
    {
        return R.toAjax(resBannerService.insertResBanner(resBanner));
    }

    /**
     * 修改轮播图
     */
    @PutMapping
    public R edit(@RequestBody ResBanner resBanner)
    {
        return R.toAjax(resBannerService.updateResBanner(resBanner));
    }

    /**
     * 删除轮播图
     */
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id)
    {
        return R.toAjax(resBannerService.deleteResBannerById(id));
    }

}
